import { defineStore } from 'pinia'
import request from '@/utils/request'
import { ApiRes, BannerItem, BrandItem, HotItem, NewItem, ProductItem, SpecialItem } from '@/types'

export default defineStore ('home',{
  state() {
      return {
        bannerList: [] as BannerItem[],
        newList: [] as NewItem[],
        hotLitst: [] as HotItem[],
        brandList: [] as BrandItem[],
        productList: [] as ProductItem[],
        specialList: [] as SpecialItem[]
      }
  },
  actions:{
    async getBannerList(){
      const res = await request.get<ApiRes<BannerItem[]>>('/home/banner')
      // console.log(res)
      this.bannerList = res.data.result
      
    },
    async getNewList(){
      const res = await request.get<ApiRes<NewItem[]>>('/home/new')
      // console.log(res)
      this.newList = res.data.result
    },
    async getHotList(){
      const res = await request.get<ApiRes<HotItem[]>>('/home/hot')
      // console.log(res)
      this.hotLitst = res.data.result
      
    },
    async getBrandList(){
      const res = await request.get<ApiRes<BrandItem[]>>('/home/brand')
      // console.log(res)
      this.brandList = res.data.result
      
    },
    async getProductList(){
      const res = await request.get<ApiRes<ProductItem[]>>('/home/goods')
      // console.log(res)
      this.productList = res.data.result
      
    },
    async getSpecialList(){
      const res = await request.get<ApiRes<SpecialItem[]>>('/home/special')
      // console.log(res)
      this.specialList = res.data.result
      
    }
  },
  getters:{}
})